﻿using AbpAPI;
using AbpAPIWeb2.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace AbpAPIWeb2.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public IStudentService studentService { get; set; }

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        public async Task<string> GetName()
        {
            string name =await studentService.GetNameAsync();
         
            return name;
        }

        public async Task<int> GetAge()
        {
            var age = await studentService.GetAgeAsync();
            if(age==null)
            {
                return 0;
            }
            return age;
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}